<?php

class Core_Model_Design_Collection_Page_Template extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('design/page_template');
        $this->from('{t}design_page_template', 'a')->field('a.*');
    }

    public function joinWebsiteTheme(){
         return $this->innerJoin('{t}design_website_theme', 'd', 'a.website_theme_id', 'd.id')
                    ->field('d.name', 'website_theme_name')
                    ->field('d.title', 'website_theme_title');
    }

    public function joinPageTheme(){
        return $this->innerJoin('{t}design_page_theme', 'c', 'a.page_theme_id', 'c.id')
                    ->field('c.name', 'page_theme_name')
                    ->field('c.title', 'page_theme_title')
                    ->field('c.type', 'page_theme_type');
    }

    public function joinArea() {
        return $this->innerJoin('{t}global_area', 'b', 'a.area_id', 'b.id')
                    ->field('c.name', 'area_name');
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'pagethemeid':
                return $this->addParameter('pageThemeId', $arg)->eq('a.page_theme_id', ':pageThemeId:s');
            case 'areaid':
                return $this->addParameter('areaId', $arg)->eq('a.area_id', ':areaId:s');
            case 'enabled':
                return $this->addParameter('enabled', $arg)->eq('a.enabled', ':enabled:i');
            case 'filename':
                return $this->addParameter('fileName', $arg)->eq('a.file_name', ':fileName:s');
        }
        return parent::filterBy($name, $arg);
    }
}

